import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/wallet_controller.dart';
import '../l10n/app_localizations.dart';

class WithdrawalTabs extends StatelessWidget {
  const WithdrawalTabs({super.key});

  @override
  Widget build(BuildContext context) {
    final WalletController controller = Get.find();
    final l10n = AppLocalizations.of(context);

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      child: Column(
        children: [
          // 标题
          Text(
            l10n.withdrawalHistory,
            style: TextStyle(
              color: const Color(0xFF00FFFF),
              fontSize: 18.sp,
              fontWeight: FontWeight.bold,
            ),
          ),

          SizedBox(height: 16.h),

          // 标签页
          Obx(
            () => Row(
              children:
                  controller.tabs.asMap().entries.map((entry) {
                    final index = entry.key;
                    final tab = entry.value;
                    final isSelected = index == controller.selectedTab.value;

                    return Expanded(
                      child: GestureDetector(
                        onTap: () => controller.selectTab(index),
                        child: Container(
                          margin: EdgeInsets.symmetric(horizontal: 4.w),
                          padding: EdgeInsets.symmetric(vertical: 12.h),
                          decoration: BoxDecoration(
                            color:
                                isSelected
                                    ? const Color(0xFF00FFFF).withOpacity(0.2)
                                    : const Color(0xFF1A1F3A).withOpacity(0.8),
                            borderRadius: BorderRadius.circular(8.r),
                            border: Border.all(
                              color:
                                  isSelected
                                      ? const Color(0xFF00FFFF)
                                      : const Color(0xFF0084FF),
                              width: 1,
                            ),
                          ),
                          child: Center(
                            child: Text(
                              _getLocalizedTabText(tab, l10n),
                              style: TextStyle(
                                color:
                                    isSelected
                                        ? const Color(0xFF00FFFF)
                                        : Colors.white,
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w600,
                              ),
                            ),
                          ),
                        ),
                      ),
                    );
                  }).toList(),
            ),
          ),
        ],
      ),
    );
  }

  String _getLocalizedTabText(String tab, AppLocalizations l10n) {
    switch (tab) {
      case 'WITHDRAWING':
        return l10n.withdrawing;
      case 'PAID':
        return l10n.paid;
      default:
        return tab;
    }
  }
}
